package com.xfhy.selectcity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.xfhy.selectcity.data.Area;
import com.xfhy.selectcity.data.AreaViewModel;
import com.xfhy.selectcity.select.SelectProvinceActivity;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    private AreaViewModel mAreaViewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mAreaViewModel = new ViewModelProvider(this).get(AreaViewModel.class);

        findViewById(R.id.btn_select).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, SelectProvinceActivity.class));
            }
        });

        /*mAreaViewModel.getAllWords().observe(this, new Observer<List<Area>>() {
            @Override
            public void onChanged(List<Area> areas) {
                Log.d("xfhy_area", "个数：" + areas.size());
            }
        });*/

        /*mAreaViewModel.queryCitiesByProvince("四川").observe(this, new Observer<List<Area>>() {
            @Override
            public void onChanged(List<Area> areas) {
                Log.d("xfhy_area", "个数：" + areas.size());
            }
        });*/

        /*mAreaViewModel.queryAreasByCity("成都").observe(this, new Observer<List<Area>>() {
            @Override
            public void onChanged(List<Area> areas) {
                Log.d("xfhy_area", "个数：" + areas.size());
            }
        });*/
        mAreaViewModel.queryAllProvinceName().observe(this, new Observer<List<String>>() {
            @Override
            public void onChanged(List<String> strings) {
                Log.d("xfhy_area", "个数：" + strings.size());
                /*StringBuilder stringBuilder = new StringBuilder();
                for (String string : strings) {
                    stringBuilder.append("\"").append(string).append("省").append("\"").append(",");
                }
                Log.d("xfhy_area", "内容：" + stringBuilder.toString());*/
            }
        });

    }
}